package nine_RemoveDuplicatesFromSortedArray;

public class CSolution {

    public static void main(String[] args) {
        System.out.println("aa");
        System.out.println(removeDuplicates(new int[]{1, 1, 2}));
        System.out.println(removeDuplicates(new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}));
    }

    private static int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int head = 0;
        int end = 0;
        for (int i = 0; i < nums.length; i++) {
            while (end < nums.length) {
                if (nums[head] != nums[end]) {
                    nums[++head] = nums[end];
                }
                end++;
            }
        }
        return ++head;
    }
}
